﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Jemgine.Data
{
    [Engine.Category("System"), Engine.Node]
	public class Waypoint : ScriptNode, Data.Rotatable, Data.EditorDrawable
	{
        public float Angle { get; set; }
        public int Pause { get; set; }

        public Waypoint()
        {
            Angle = 0.0f;
            Pause = 0;

            AddReference("Next", null);
        }

        #region Rotatable Members

        object Jemgine.Data.Rotatable.PrepareToRotate()
        {
            return Angle;
        }

        void Jemgine.Data.Rotatable.ApplyRotation(object Tag, float Rotation)
        {
            float OriginalAngle = (float)Tag;
            Angle = OriginalAngle + Rotation;
        }

        void Jemgine.Data.Rotatable.Snap(Jemgine.Data.Snapper Snapper)
        {
            Angle = Snapper.SnapRotation(Angle);
        }

        #endregion

        #region EditorDrawable Members

        void Jemgine.Data.EditorDrawable.Draw(int ID, Jemgine.Data.EditorDrawData Context, Jemgine.Data.SelectionType Selected)
        {
            base.Draw(ID, Context, Selected);

            Context.Renderer.Color = Color.Gold.ToVector4();

            Context.Renderer.DrawLine(Position,
                Position + Vector2.Transform(new Vector2(0, 4), Matrix.CreateRotationZ(Angle)),
                0.2f);
        }
        
        #endregion
    }
}
